import Vue from 'vue';
import VueRouter from 'vue-router';
import NProgress from 'nprogress';


const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err);
};
//解决vue-router重复点击报错问题（this.$router.push()）
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err);
};
import {
    whs
} from './whs';
import {
    sd
} from './sd';
import {
    hys
} from './hys';
import {
    xqh
} from './xqh';
import {
    wyw
} from './wyw';
import {
    ldy
} from './ldy';

Vue.use(VueRouter);

const routes = [...sd, ...whs, ...hys, ...xqh, ...wyw, ...ldy];
const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
});

router.beforeEach((_, _q, next) => {
    if (_.name == 'My') {
        if (sessionStorage.getItem("login")) {
            next()
        } else {
            next('/account')
        }
    } else {
        NProgress.start();
        next();
    }

});

router.afterEach(() => {
    NProgress.done();
});


export default router;